package pub.aspect;

import javax.annotation.Resource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class AuthManage {
	@Resource
	private HibernateTemplate template;
	 public void after(JoinPoint jp) {  
	        System.out.println("log Ending method: " + jp.getTarget().getClass().getName() + "." + jp.getSignature().getName());  
	    }  
	  
	    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {  
	        long time = System.currentTimeMillis();  
	        Object retVal = pjp.proceed();  
	        time = System.currentTimeMillis() - time;  
	        System.out.println("process time: " + time + " ms");  
	        return retVal;  
	    }  
	  
	    public void before(JoinPoint jp) {  
	        System.out.println("log Begining method: " + jp.getTarget().getClass().getName() + "." + jp.getSignature().getName()); 
	        System.out.println(jp.getArgs());
	        //Integer roleId=((Userinfo)session.getAttribute("userinfo")).getRole().getId();
	        
	        //List<Tablerole> list=template.find(" from Tablerole WHERE roleId='"+roleId+"' AND tableName='"+jp.getArgs()[0]+"'");
	        
	       // System.out.println(list.get(0));
	    } 
	    
	    public void afterReturn(JoinPoint jp) {  
	        System.out.println("log Begining method: " + jp.getTarget().getClass().getName() + "." + jp.getSignature().getName());  
	    }  
	    
	    public void afterThrow(JoinPoint jp, Throwable ex) {  
	        System.out.println("method " + jp.getTarget().getClass().getName() + "." + jp.getSignature().getName() + " throw exception");  
	        System.out.println(ex.getMessage());  
	    }  
}
